package com.carryking.smart.rpc.netty;

import com.carryking.smart.rpc.netty.channel.ClientChannel;
import com.carryking.smart.rpc.netty.code.RequestEntityEncoder;
import com.carryking.smart.rpc.netty.code.ResponseEntityDecoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldPrepender;

/**
 * Created by jincarry on 2018/1/10.
 */
public class CustomerChannelInitializer extends ChannelInitializer<SocketChannel> {
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(1024*1024, 0, 4,0,4));
        ch.pipeline().addLast(new LengthFieldPrepender(4));
        ch.pipeline().addLast(new RequestEntityEncoder());
        ch.pipeline().addLast(new ResponseEntityDecoder());

        //test
        ch.pipeline().addLast(new ClientChannel());
    }
}
